import { combineReducers } from "redux";
import type from "./action-type";

const reducer = {};

const page = {
  size: 10,
  num: 1
};
reducer.page = (state = page, action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_PAGE_NUM:
      return { ...state, num: payload };
    case type.SET_PAGE_SIZE:
      return { ...state, size: payload };
    default:
      return state;
  }
};

reducer.totalNum = (state = 0, action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_TOTAL_NUM:
      return payload;
    default:
      return state;
  }
};

reducer.list = (state = [], action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_LIST:
      return payload;
    default:
      return state;
  }
};

reducer.loading = (state = false, action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_LOADING:
      return payload;
    default:
      return state;
  }
};

reducer.startDate = (state = 0, action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_START_DATE:
      return payload;
    default:
      return state;
  }
};

reducer.endDate = (state = 0, action = {}) => {
  const { payload } = action;

  switch (action.type) {
    case type.SET_END_DATE:
      return payload;
    default:
      return state;
  }
};

export default combineReducers({ ...reducer });
